package com.fs.common.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * MQ配置
 *
 * @author  LiuQi 2025/6/11-13:05
 * @version V1.0
 **/
@Configuration
@ConditionalOnProperty(prefix = "spring.rabbitmq", name = "enabled", havingValue = "true")
public class MqConfiguration {
    @Value("${spring.rabbitmq.queues.dept}")
    private String deptQueue;

    @Value("${spring.rabbitmq.queues.user}")
    private String userQueue;

    @Bean
    public Binding createDeptQueue() {
        Queue deptQueue =  new Queue(this.deptQueue);
        return BindingBuilder.bind(deptQueue).to(new TopicExchange(this.deptQueue + ".topic"))
                .with("*");
    }

    @Bean
    public Binding createUserQueue() {
        Queue userQueue = new Queue(this.userQueue);
        return BindingBuilder.bind(userQueue).to(new TopicExchange(this.userQueue + ".topic"))
                .with("*");
    }
}
